package de.revdev.llt.module.classroom;

import de.revdev.llt.module.classroom.interfaces.ClassRoomInterface;
import de.revdev.llt.module.filecardboxes.FileCardBox;
import de.revdev.llt.module.interfaces.EntityInterface;
import de.revdev.llt.module.useradministrtaion.User;
import java.io.Serializable;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

/**
 *
 * @author f.lindermaier
 */
@Entity
@Table(name = "tbl_publicclassroom")
public class PublicClassRoom implements Serializable, EntityInterface, ClassRoomInterface {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    @NotNull
    @Size(min = 2, max = 30)
    private String title;
    @OneToMany(mappedBy = "publicClassRoom", cascade = CascadeType.ALL)
    private List<Participants> participants;
    @OneToOne
    private User owner;
    @ManyToMany(targetEntity = FileCardBox.class)
    @JoinTable(name = "tbl_publicclassroom_filecardbox", joinColumns =
    @JoinColumn(name = "id_publicclassroom", referencedColumnName = "id"), inverseJoinColumns =
    @JoinColumn(name = "id_filecardbox", referencedColumnName = "id"))
    private List<FileCardBox> fileCardBoxes;

    @Override
    public Long getId() {
        return id;
    }

    @Override
    public void setId(Long id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public User getOwner() {
        return owner;
    }

    public void setOwner(User owner) {
        this.owner = owner;
    }

    public List<Participants> getParticipants() {
        return participants;
    }

    public void setParticipants(List<Participants> participants) {
        this.participants = participants;
    }

    @Override
    public List<FileCardBox> getFileCardBoxes() {
        return fileCardBoxes;
    }

    @Override
    public void setFileCardBoxes(List<FileCardBox> fileCardBoxes) {
        this.fileCardBoxes = fileCardBoxes;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof PublicClassRoom)) {
            return false;
        }
        PublicClassRoom other = (PublicClassRoom) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "de.revdev.llt.bean.entities.PublicClassroom[ id=" + id + " ]";
    }
}
